<!DOCTYPE html>
<html>
<head>
	<title>用户修改</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="css/mui.css" rel="stylesheet"/>
	<link href="css/common.css" rel="stylesheet"/>
	<link href="js/layui/css/layui.css" rel="stylesheet"/>
		<style>
			input{
				border:0px;
				font-size:16px;
			}
			select{
				width:80%;
				height:39px;
			}
			.yhxg-input-div{
				width: 94%;
				margin-left:3%;
				margin-top:5%;
			}
			.one{
				margin-top:10%;
			}
		</style>
</head>
<body class="bg">
	<header class="mui-bar mui-bar-nav mui-bar-transparent bg main-header" >
	<div class="back"><a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left back" >返回</a></div>
	<div class="back" style="text-align: center;"><a class="mui-icon  mui-pull-center back" >添加修改</a></div>

   </header>

	<div class="mui-content bg" >
		<div class="yhxg-input-div one">
			<div class="input-lable">用户名</div><div class="input-div"><input type="text" value="" disabled="false" id="user_account" /></div>
		</div>
		<div class="yhxg-input-div">
			<div class="input-lable">密码</div><div class="input-div"><input type="text"  value="" id="user_pwd"/></div>
		</div>
		<div class="yhxg-input-div">
			<div class="input-lable">姓名</div><div class="input-div"><input type="text"   value="" id="user_name"/></div>
		</div>
		<div class="yhgl-select-dev">
			<div class="input-lable">角色</div><div class="input-div">
			    <select id="user_type">
					<option value="B">班长</option>
					<option value="Z">质检员</option>
					<option value="F">复检员</option>
				</select>
			</div>
		</div>
		<div class="yhgl-select-img">
			<img src="img/xiala.png" />
		</div>
		<div class="yhgl-select-dev">
			<div class="input-lable">地磅开关</div>
			<div class="input-div"> 
				<select id="switch"  style="width:80%;height:39px;">
					<option value="1">开</option>
					<option value="0">关</option>
				</select>
			</div>
		</div>
		<div  class="yhgl-select-img">
			<img src="img/xiala.png" />
		</div>
		
		<div class="yhgl-btn-dev">
			<button class="btn1" onclick="save()">保 存</button>
		</div>
		<div class="yhgl-btn-dev">
			<button class="btn2" onclick="back()">返 回</button>
		</div>		
     </div>
	</form>
	</div>
</body>
<script src="js/mui.js"></script>
<script src="js/jquery.min.js.js" type="text/javascript" charset="utf-8"></script>
<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	mui.init();
    mui.plusReady(function(){
		var old_back = mui.back;
		mui.back = function() {
			var wobj = plus.webview.getWebviewById("yhgl.html");
			wobj.reload(true);
			old_back();
		}
	})
	var data_id = location.href.split('?')[1];
	var user = Db.query('user','');
	var userinfo = user[data_id];
	$("#user_account").val(userinfo.ID);
	$("#user_pwd").val(userinfo.PWD);
	$("#user_name").val(userinfo.UNAME);
	$("#user_type").val(userinfo.USERS1);
	$("#switch").val(userinfo.USERS2);
	
	function back(){
		mui.back();
	}
	
	function save(){
    	var user_pwd = $.trim($("#user_pwd").val());
    	var user_name = $.trim($("#user_name").val());
    	var user_type = $("#user_type").val();
    	var _switch = $("#switch").val();
    	if(!user_pwd){ mui.toast('请输入密码'); return; }
    	if(user_pwd.length>10){ mui.toast('密码长度不能超过10位数'); return; }
    	userinfo.PWD = user_pwd;
    	userinfo.UNAME = user_name;
    	userinfo.USERS1 = user_type;
   		userinfo.USERS2 = _switch;
    	user[data_id] = userinfo;
		Db.insert('user',user);
    	mui.toast('修改成功');
    	mui.back();
	}
</script>
</html>